package com.csw.android.ffmpegtest.media

import androidx.lifecycle.LifecycleOwner
import com.csw.android.ffmpegtest.media.play.AACPlayer
import com.csw.android.ffmpegtest.media.play.WAVPlayer
import com.csw.android.ffmpegtest.media.play.base.IPlayer
import com.csw.android.ffmpegtest.media.play.base.IPlayerListener
import com.csw.android.ffmpegtest.media.record.AACRecord
import com.csw.android.ffmpegtest.media.record.WAVRecord
import com.csw.android.ffmpegtest.media.record.base.IRecordListener
import com.csw.android.ffmpegtest.media.record.base.IRecorder
import java.util.*

object MediaFactory {

    fun getRecorder(
        type: String,
        lifecycleOwner: LifecycleOwner,
        filePath: String,
        listener: IRecordListener
    ): IRecorder? {
        return when (type.toLowerCase(Locale.getDefault())) {
            "wav" -> WAVRecord(filePath, lifecycleOwner, listener)
            "aac" -> AACRecord(filePath, lifecycleOwner, listener)
            else -> null
        }
    }

    fun getPlayer(
        type: String,
        lifecycleOwner: LifecycleOwner,
        filePath: String,
        listener: IPlayerListener
    ): IPlayer? {
        return when (type.toLowerCase(Locale.getDefault())) {
            "wav" -> WAVPlayer(filePath, lifecycleOwner, listener)
            "aac" -> AACPlayer(filePath, lifecycleOwner, listener)
            else -> null
        }
    }
}